﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Collections.Generic;
using CTEM.Models;
using CTEM.Controllers.BUS;
using CTEM.Controllers.Global;

namespace CTEM.ModuleForms.ManageReport
{
    public partial class XtraReport1 : DevExpress.XtraReports.UI.XtraReport
    {
      

        public XtraReport1()
        {
            InitializeComponent();
        }

        public void BindData(WorkerSalaryDTO workerSalary)
        {
            XRTableRow rowtitle = new XRTableRow();
            rowtitle.Name = "row 1";
            rowtitle.WidthF = 850;
            rowtitle.HeightF = 30;
            // full name
            XRTableCell clName = new XRTableCell();
            //clName.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
            //    new DevExpress.XtraReports.UI.XRBinding("Text", null, worker.Fullname)});
            clName.Name = "clName";
            clName.Text = "Tên Công Nhân";
            clName.WidthF = 160;
            clName.HeightF = 30;
            clName.BackColor = System.Drawing.Color.RoyalBlue;
            clName.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            rowtitle.Cells.Add(clName);

            // postion
            XRTableCell clPostion = new XRTableCell();
            //clPostion.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
            //    new DevExpress.XtraReports.UI.XRBinding("Text", null, worker.Position)});
            clPostion.Name = "clPostion";
            clPostion.Text = "Chức Vụ";
            clPostion.WidthF = 100;
            clPostion.HeightF = 30;
            clPostion.BackColor = System.Drawing.Color.RoyalBlue;
            clPostion.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            rowtitle.Cells.Add(clPostion);

            // salary
            XRTableCell clSalary = new XRTableCell();
            //clSalary.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
            //    new DevExpress.XtraReports.UI.XRBinding("Text", null, Convert.ToString(worker.Salary))});
            clSalary.Name = "clSalary";
            clSalary.Text = "Công Nhật";
            clSalary.WidthF = 80;
            clSalary.HeightF = 30;
            clSalary.BackColor = System.Drawing.Color.RoyalBlue;
            clSalary.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            rowtitle.Cells.Add(clSalary);
            if (workerSalary.listWork.Count > 0)
            {
                foreach (var day in workerSalary.listWork[0].dayWorking)
                {


                    XRTableCell clDate = new XRTableCell();
                    //clDate.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
                    //    new DevExpress.XtraReports.UI.XRBinding("Text", null, day.Date.ToString("dd"))});
                    clDate.Name = "clDate";
                    clDate.Text = day.Date.ToString("dd");
                    clDate.WidthF = 30;
                    clDate.HeightF = 30;
                    clDate.BackColor = System.Drawing.Color.RoyalBlue;
                    clDate.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                    rowtitle.Cells.Add(clDate);



                }

                tableWorker.Rows.Add(rowtitle);
                foreach (var worker in workerSalary.listWork)
                {
                    XRTableRow xrTableRow = new XRTableRow();
                    xrTableRow.Name = "xrTableRow2";
                    xrTableRow.WidthF = 850;
                    xrTableRow.HeightF = 30;
                    // full name
                    XRTableCell cltName = new XRTableCell();
                    //clName.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
                    //    new DevExpress.XtraReports.UI.XRBinding("Text", null, worker.Fullname)});
                    cltName.Name = "cltName";
                    cltName.Text = worker.Fullname;
                    cltName.WidthF = 160;
                    cltName.HeightF = 30;
                    xrTableRow.Cells.Add(cltName);

                    // postion
                    XRTableCell cltPostion = new XRTableCell();
                    //clPostion.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
                    //    new DevExpress.XtraReports.UI.XRBinding("Text", null, worker.Position)});
                    cltPostion.Name = "cltPostion";
                    cltPostion.Text = worker.Position;
                    cltPostion.WidthF = 100;
                    cltPostion.HeightF = 30;
                    xrTableRow.Cells.Add(cltPostion);

                    // salary
                    XRTableCell cltSalary = new XRTableCell();
                    //clSalary.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
                    //    new DevExpress.XtraReports.UI.XRBinding("Text", null, Convert.ToString(worker.Salary))});
                    cltSalary.Name = "cltSalary";
                  
                    cltSalary.Text =  worker.Salary.ToString("n0");
                    cltSalary.WidthF = 80;
                    cltSalary.HeightF = 30;
                    xrTableRow.Cells.Add(cltSalary);
                    // table


                    foreach (var day in worker.dayWorking)
                    {

                        XRTableCell clValue = new XRTableCell();
                        //clValue.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
                        //new DevExpress.XtraReports.UI.XRBinding("Text", null, Convert.ToString(day.Value))});
                        clValue.Name = "clValue";
                        clValue.Text = Convert.ToString(day.Value);
                        clValue.WidthF = 30;
                        clValue.HeightF = 30;
                        xrTableRow.Cells.Add(clValue);

                    }
                    tableWorker.Rows.Add(xrTableRow);

                }


                bindingSource1.DataSource = workerSalary;


            }
        }
      

    }
}

